<?php  
session_start();

require_once("conf.php");
require_once("dbConnect.php");
require_once("mysql.php");
require_once("datesFunctions.php");

ini_set('register_globals', "off");


/***************************************************************/
//Nombre: saveConfessionByCategory
//Parametros:
//Comentarios:
//
//
function saveMustDo($description, $picture, $active){
	$date = date("Y-m-d H:i:s");
	$sql="INSERT INTO mustdo (description, picture, active, datetime) values ('$description','$picture', '$active', '$date')";
	//echo "<br>".$sql."<br>";
	$result = doSQL_Write($sql);

	return $result;
}

/***************************************************************/
//Nombre: getMustdoByCategories
//Parametros: 
//Comentarios: 
//
//
function getMustdo($page){
	
	$per_page = 2;
	$v_data = array();
	$isLastPage = false;
	
	$sqlCount="SELECT id FROM mustdo WHERE active = '1' AND banned='0' ORDER BY datetime DESC";
	$sql="SELECT id, description, picture, datetime FROM mustdo WHERE active = '1' AND banned='0' ORDER BY datetime DESC";
	
	$totalRows = count(doSQL_Read($sqlCount));
	$pages = ceil($totalRows/$per_page);
	
	if($page <= $pages){
		$start    = ($page - 1) * $per_page;
		$sql      = $sql." LIMIT $start, $per_page";	
		//echo "<br>".$sql."<br>";
		$v_data = doSQL_Read($sql); 
	} 
	
	if($page >= $pages){
		$isLastPage = true;
	}
	
	$result["MustDo"] = $v_data;
	$result["lastPage"] = $isLastPage;
	
	return $result;
}
?>